package com.framework.controller;

import com.framework.entity.or.AppDiscoverArticle;
import com.framework.entity.or.OrBanner;
import com.framework.entity.sys.SysNotice;
import com.framework.entity.ter.StarposMcc;
import com.framework.exception.util.RespResult;
import com.framework.service.*;
import com.framework.service.app.AppDiscoverArticleService;
import com.framework.service.app.AppDiscoverCoverService;
import com.framework.view.RegistStarposBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 功能描述:h5统一接口 不需要参数加密校验和token
 *
 * @author ck
 * @date 2018/11/16 14:01
 */
@RestController
@Api(value="h5统一接口",tags={"h5统一接口"})
@RequestMapping(value = "h5")
public class H5ApiController {

	@Autowired
	private AgentService agentService;
	@Autowired
	private NoticeReadService noticeReadService;
	@Autowired
	private BannerService bannerService;

	@Autowired
	private StarPosMccService starPosMccService;

	@Autowired
	private MerchantService merchantService;

	@Autowired
	private  TerminalTypeService terminalTypeService;

	@Autowired
	private AppDiscoverArticleService appDiscoverArticleService;

	/**
	 * H5上注册
	 * @param phone
	 * @param password
	 * @param confPassword
	 * @param smsCode
	 * @param pid
	 * @param name
	 * @return
	 */
	@PostMapping("notValidate/register")
	@ApiOperation("H5上注册")
	@ApiImplicitParams({
			@ApiImplicitParam(name="phone",value="手机号码",dataType="string", paramType = "query" ,required = true),
			@ApiImplicitParam(name="password",value="密码",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="confPassword",value="确认密码",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="smsCode",value="验证码",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="pid",value="推荐码",dataType="Long", paramType = "query",required = true),
			@ApiImplicitParam(name="name",value="真实姓名",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="deptId",value="渠道id",dataType="Long", paramType = "query",required = true)})
	public RespResult register(String phone, String password, String confPassword, String smsCode, Long pid, String name,Long deptId) {
		agentService.register(phone,password,confPassword,smsCode,pid,name, deptId);
		return RespResult.ok();
	}

	/**
	 * 系统通知详情
	 * @param noticeNo
	 * @return
	 */
	@GetMapping("notValidate/querySysNoticeInfo")
	@ApiOperation("系统通知详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name="noticeNo",value="唯一id",dataType="string", paramType = "query",required = true)
	})
	public RespResult querySysNoticeInfo(String token,String noticeNo) {
		SysNotice info = noticeReadService.querySysNoticeInfo(token,noticeNo);
		return RespResult.ok().put("info",info);
	}

	/**
	 * Banner图详情
	 * @param id
	 * @return
	 */
	@GetMapping("notValidate/geHomeBanner")
	@ApiOperation("首页轮播图")
	@ApiImplicitParams({
			@ApiImplicitParam(name="id",value="所属Banner图Id",dataType="long", paramType = "query",required = true)
	})
	public RespResult geHomeBanner(Long id) {
		OrBanner info = bannerService.queryBannerInfoById(id);
		return RespResult.ok().put("info",info);
	}

	/**
	 * 获取商户类别列表 用户星pos进件
	 * @param mccId
	 * @return
	 */
	@GetMapping("notValidate/getMccListById")
	@ApiOperation("获取商户类别列表 用户星pos进件")
	@ApiImplicitParam(name="mccId" ,value = "商户类别id" ,type = "int" ,required = true,paramType = "query")
	public RespResult getMccListById(Integer mccId){
		List<StarposMcc> list = starPosMccService.getMccListById(mccId);
		return RespResult.ok().put("list",list);
	}

	/**
	 * 星pos进件
	 * @param bean
	 * @param token
	 * @return
	 */
	@PostMapping("notValidate/registStarpos")
	@ApiOperation("用户星pos进件")
	public RespResult registStarpos(RegistStarposBean bean,String token){
		Map<String, Object> map = agentService.registStarpos(bean, token);
		return RespResult.ok(map);
	}


	/**
	 * 上传图片
	 * @param mercId
	 * @param url1
	 * @param url2
	 * @param url3
	 * @return
	 */
	@PostMapping("notValidate/uploadStarPosImg")
	@ApiOperation("上传图片")
	public RespResult uploadStarPosImg(String mercId,String url1,String url2,String url3){
		Map<String, Object> map = agentService.uploadStarPosImg(mercId, url1, url2, url3);
		return RespResult.ok(map);
	}

	/**
	 * 微信商户报备
	 * @param merchantName
	 * @param phone
	 * @param sn
	 * @param model
	 * @param merchantNo
	 * @param agentPhone
	 * @param agentId
	 * @return
	 */
	@PostMapping("notValidate/reportMerByWX")
	@ApiOperation("微信商户报备")
	@ApiImplicitParams({
			@ApiImplicitParam(name="merchantName",value="商户名称",dataType="string", paramType = "query" ,required = true),
			@ApiImplicitParam(name="phone",value="手机号码",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="sn",value="机具SN号",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="model",value="机具类型",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="merchantNo",value="商户号",dataType="string", paramType = "query"),
			@ApiImplicitParam(name="agentPhone",value="客户经理手机号",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="agentId",value="推荐码",dataType="Long", paramType = "query",required = true)
	})
	public RespResult reportMerByWX(String merchantName, String phone, String sn, String model,String merchantNo,String agentPhone,Long agentId){
		merchantService.reportMerByWX(merchantName,phone,sn,model,merchantNo,agentPhone,agentId);
		return RespResult.ok();
	}

	/**
	 * 根据渠道获取类型
	 * @param deptId
	 * @return
	 */
	@GetMapping("notValidate/getTypeAndModel/{deptId}")
	@ApiOperation("根据渠道获取类型")
	@ApiImplicitParam(name="deptId",value="渠道id",dataType="Long", paramType = "query",required = true)
	public  RespResult getTerminalTypeAndModel(@PathVariable Long deptId){
		List<Map<String, Object>> list = terminalTypeService.getTypeAndModel(deptId);
		return RespResult.ok().put("list",list);
	}

	/**
	 * 根据文章id获取内容
	 * @param id
	 * @return
	 */
	@GetMapping("notValidate/getArticleById/{id}")
	@ApiOperation("根据文章id获取内容")
	@ApiImplicitParam(name="deptId",value="渠道id",dataType="Long", paramType = "query",required = true)
	public RespResult getArticleById(@PathVariable int id){
		AppDiscoverArticle appDiscoverArticle = appDiscoverArticleService.selectById(id);
		return RespResult.ok().put("article",appDiscoverArticle);
	}

}
